package com.lagou.edu.ctrl;

import com.lagou.api.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.util.StringUtils;

@Service
public class EmailImpl  implements EmailService {

    @Autowired
    private JavaMailSenderImpl javaMailSender;

    @Override
    public boolean send(String email, String code) {
        if (StringUtils.isEmpty(email)) {
            return false;
        }
        if (StringUtils.isEmpty(code)) {
            return false;
        }
        //send email

        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("验证码");
        message.setText(code);
        message.setTo(email);
        message.setFrom("jayqqaa12@sina.cn");
        javaMailSender.send(message);

        return true;
    }
}
